package club.wx3609.images.controller;

import club.wx3609.images.Utils.IsNullUtils;
import club.wx3609.images.entity.User;
import club.wx3609.images.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
public class ManagementIndexController {

    @Resource
    private UserService userService;

    @RequestMapping("/mIndex")
    public String resultHtml(Map<String,Object> map,HttpServletRequest request){
        map.put("User",request.getSession().getAttribute("User"));
        return "ManagementIndex";
    }

    @PostMapping("/toIndex")
    public String toIndex(String userNumber,Map<String,Object> map){
        User user=userService.registerVerification(userNumber);
        if(user!=null) {
            map.put("User",user);
            return "Index";
        }
        return "error";
    }

    @GetMapping("/signOut")
    public String signOut(HttpServletRequest request){
        request.getSession().setAttribute("GLY",null);
        return "Login";
    }
}
